﻿@page "/js"

<button @onclick="Alert">提示</button>

<button @onclick="Propmt">弹出框</button>

你输入的是： @Value

<p>
    <button @onclick="Add">Add</button>
    <button @onclick="AddAsync">AddAsync</button>
</p>

@inject IJSRuntime JS

@code {
    string? Value { get; set; }
    async Task Alert()
    {
        await JS.InvokeVoidAsync("hello");
    }

    async Task Propmt()
    {
        var value = await JS.InvokeAsync<string>("prompt", "请输入名字");
        Value = value;
    }

    async Task Add()
    {
        var js = DotNetObjectReference.Create(new JsFunc());

        await JS.InvokeVoidAsync("add", js);
    }

    async Task AddAsync()
    {
        var js = DotNetObjectReference.Create(new JsFunc());

        await JS.InvokeVoidAsync("addAsync", js);
    }
}